<style lang="less" scoped>

  .div-order-manage-sty {
    height: 92%;
    display: flex;

    .el-row {
      margin-bottom: 20px;
      &:last-child {
        margin-bottom: 0;
      }
    }

    .el-col {
      border-radius: 4px;
    }

    .bg-purple {
      background: #ffffff;
    }

    .grid-content {
      border-radius: 4px;
      min-height: 36px;
    }

    .el-button {
      width: 100%;
      margin: auto;
    }

    .el-col-2 {
      text-align: center;
    }

    .f-b1 {
      border-top: 1px solid #c8c8c8;
      /*border-left: 1px solid #c8c8c8;*/
      /*border-right: 1px solid #c8c8c8;*/
      line-height: 36px;
      margin-bottom: 0;
    }

    .f-bb1 {
      border-bottom: 1px solid #c8c8c8;
    }

    .f-bo {
      border: 0;
    }

    .f-w70 {
      width: 70%;
    }

    .f-mb {
      margin-bottom: 0;
    }

    .f-fr {
      float: right;
    }

    .f-wa {
      width: auto;
    }

    .f-mt {
      margin-top: 20px;
    }

    .f-mt10 {
      margin-top: 10px;
    }

    .f-mr20 {
      margin-right: 20px;
    }

    .f-ml10 {
      margin-left: 10px;
    }

    .f-mr10 {
      margin-right: 10px;
    }

    .f-bc {
      background: #eef1f6;
    }

    .div-content-sty {
      width: 99%;
      float: right;
    }

    .f-mb10 {
      margin-bottom: 10px;
    }

    li {
      list-style-type: none;
    }

    .f-mt5 {
      margin-top: 5px;
    }

    .f-mb5 {
      margin-bottom: 5px;
    }

    .f-mr5 {
      margin-right: 5px;
    }

    .f-tc {
      color: #20a0ff;
    }

    .f-txc {
      text-align: center;
    }

    .active {
      display: none;
    }

    .f-pa {
      position: absolute;
    }

    .f-w20 {
      width: 20px;
    }

    .f-h20 {
      height: 20px;
    }

    .f-w80 {
      position: absolute;
      margin-top: -6px;
      width: 80px;
    }

    .f-cr {
      color: red;
    }
  }
</style>

<template>
  <div class="div-order-manage-sty">
    <el-row>
      <el-col :span="2" style="height: 100%">
        <el-row>
          <el-button type="primary" @click="orderEnteringDialog=true">订单录入</el-button>
        </el-row>
        <el-menu default-active="2" class="el-menu-vertical-demo" @select="searchOrdersByOrderStatus">
          <el-menu-item index="2">所有订单 [{{orderNumbers.all}}]</el-menu-item>
          <el-menu-item index="orderStatus=101001001 g0;isDelete=111002002 g1">待提交 [{{orderNumbers.dtj}}]
          </el-menu-item>
          <el-menu-item index="orderStatus=101001002 g0">待确认 [{{orderNumbers.dqr}}]</el-menu-item>
          <el-menu-item index="payStatus=101003001 g0;isDelete<>111002001 g1">待支付 [{{orderNumbers.dzf}}]
          </el-menu-item>
          <el-menu-item index="signOffStatus=101009001 g0">待签收 [{{orderNumbers.dqs}}]</el-menu-item>
          <!--<el-menu-item index="orderStatus=101001007 g0">待评价 [{{orderNumbers.dth}}]</el-menu-item>-->
          <el-menu-item index="isDelete=111002001 g0">回收站 [{{orderNumbers.hsz}}]</el-menu-item>
        </el-menu>
      </el-col>
      <el-col :span="22">
        <div class="grid-content bg-purple div-content-sty f-mb10">
          <el-form ref="searchForm" label-position="right" :model="searchForm" class="f-bc"
                   label-width="120px">
            <el-row class="f-mb">
              <el-col :span="8">
                <el-form-item class="f-mb" label="订单号" prop="orderNumber">
                  <el-input v-model="searchForm.orderNumber" class="f-w70"
                            placeholder="请输入订单号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item class="f-mb" label="订单日期" prop="createDate">
                  <el-date-picker class="f-w70"
                                  v-model="searchForm.createDate"
                                  type="daterange"
                                  placeholder="选择日期范围">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item class="f-mb" label="订单来源" prop="orderSource">
                  <el-select v-model="searchForm.orderSource" class="f-w70"
                             @visible-change="searchOrderSource"
                             filterable placeholder="请选择订单来源">
                    <el-option style="width: 200px" v-for="(orderSource,index) in orderSources"
                               :label="orderSource.cnDictValname"
                               :value="orderSource.dictVal" :key="index"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="f-mb">
              <el-col :span="8">
                <el-form-item class="f-mb" label="发货客户">
                  <el-input v-model="searchForm.memberUserName" class="f-w70"
                            placeholder="请输入发货客户"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item class="f-mb" label="发货人" prop="shipmentsContactName">
                  <el-input v-model="searchForm.shipmentsContactName" class="f-w70"
                            placeholder="请输入发货人名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item class="f-mb" label="发货人手机/电话" prop="shipmentsTelephone">
                  <el-input v-model="searchForm.shipmentsTelephone" class="f-w70"
                            placeholder="请输入发货人手机/电话"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div class="f-mt f-wa">
            <el-button type="primary" class="f-wa f-fr f-ml10 f-mr20"
                       @click="resetSearchForm('searchForm')">重置
            </el-button>
            <el-button type="primary" class="f-wa f-fr f-ml10 " @click="searchOrders">查询</el-button>
            <el-button type="primary" class="f-wa f-fr f-ml10 ">导出</el-button>
            <el-button type="primary" class="f-wa f-fr f-ml10 ">导入</el-button>
          </div>
        </div>
        <div class="grid-content bg-purple div-content-sty f-mb10">
          <el-table :data="orderTableData" height="650" border @selection-change="scOrders">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column prop="date" label="订单信息" width="250">
              <template slot-scope="scope">
                <li class="f-font-20 f-mb5">
                  <a style="cursor: pointer;text-decoration:underline;color: #20a0ff"
                     @click="orderSelectDialog(scope.row)">
                    {{scope.row.orderNumber}}
                  </a>
                </li>
                <li>
                  {{scope.row.shipmentsProvince}}{{scope.row.shipmentsCity}}{{scope.row.shipmentsCounty}}
                  <img src="../../assets/start-address.gif" class="f-w20 f-h20 f-pa">
                </li>
                <li>
                  {{scope.row.sendProvince}}{{scope.row.sendCity}}{{scope.row.sendCounty}}
                  <img src="../../assets/end-address.gif" class="f-w20 f-h20 f-pa">
                </li>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="计划时间" width="250">
              <template slot-scope="scope">
                <li>提交时间&nbsp;&nbsp;{{scope.row.createDate}}</li>
                <li>
                  发运日期&nbsp;&nbsp;{{scope.row.shipmentsDate}}
                </li>
                <li v-if="scope.row.extractType===105002001">
                  计划提货&nbsp;&nbsp;{{scope.row.extractDate}} {{scope.row.extractTime}}
                </li>
                <li v-if="scope.row.extractType===105002002">{{scope.row.extractTypeName}}</li>
                <li v-if="scope.row.sendType===105001001">计划送抵&nbsp;&nbsp;{{scope.row.sendTime}}</li>
                <li v-if="scope.row.sendType===105001002">{{scope.row.sendTypeName}}</li>
              </template>
            </el-table-column>
            <el-table-column prop="address" label="货物信息" width="110">
              <template slot-scope="scope">
                <div class="f-txc">

                  <li v-if="scope.row.orderCargos.length>0">{{scope.row.orderCargos[0].cargoName}}&nbsp;&nbsp;</li>
                  <li v-if="scope.row.orderCargos.length>0">{{scope.row.orderCargos[0].amount}}&nbsp;&nbsp;件</li>
                  <li v-if="scope.row.orderCargos.length>0">{{scope.row.orderCargos[0].weight}}&nbsp;&nbsp;吨
                  </li>
                  <li v-if="scope.row.orderCargos.length>0">{{scope.row.orderCargos[0].volume}}&nbsp;&nbsp;方
                  </li>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="address" label="订单金额（元）" width="120">
              <template slot-scope="scope">
                <div class="div-w100 f-tc f-txc">
                  <li class="f-c-red f-mt10">{{scope.row.orderPrice}}元</li>
                  <li class="f-mt10" style="color: red">{{scope.row.payStatusName}}</li>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="address" label="发货人信息" width="240">
              <template slot-scope="scope">
                <li>
                  {{scope.row.shipmentsContactName}}
                </li>
                <li>
                  {{scope.row.shipmentsContactPhone}}
                  <label
                    v-if="scope.row.shipmentsContactPhone!=''&&scope.row.shipmentsContactPhone!=null&&scope.row.shipmentsContactPhone!=undefined&&scope.row.shipmentsTelephone!=''&&scope.row.shipmentsTelephone!=null&&scope.row.shipmentsTelephone!=undefined">,</label>
                  {{scope.row.shipmentsTelephone}}
                </li>
                <li>
                  {{scope.row.shipmentsStreet}}
                </li>
              </template>
            </el-table-column>
            <el-table-column prop="address" label="状态" width="100">
              <template slot-scope="scope">
                <li>{{scope.row.orderStatusName}}</li>
              </template>
            </el-table-column>
            <el-table-column prop="address" label="操作">
              <template slot-scope="scope">
                <!--待提交-->
                <el-button type="primary"
                           v-if="scope.row.orderStatus === 101001001&&scope.row.isDelete === 111002002"
                           class="f-wa f-ml10 f-mt5 f-mb5"
                           @click="orderReverse(scope.row.id,101001002,101001001,'订单提交成功')">提交
                </el-button>
                <el-button type="primary"
                           v-if="scope.row.orderStatus === 101001001&&scope.row.isDelete === 111002002"
                           class="f-wa f-ml10 f-mt5 f-mb5">编辑
                </el-button>
                <el-button type="primary"
                           v-if="scope.row.orderStatus === 101001001&&scope.row.isDelete === 111002002"
                           class="f-wa f-ml10 f-mt5 f-mb5"
                           @click="deleteOrder(scope.row.id,111002001,'订单删除成功')">删除
                </el-button>
                <el-button type="primary" v-if="scope.row.orderStatus === 101001002"
                           class="f-wa f-ml10 f-mt5 f-mb5"
                           @click="orderReverse(scope.row.id,101001001,101001002,'订单取消成功')">取消

                </el-button>
                <!--待支付-->
                <el-button type="primary"
                           v-if="scope.row.payStatus === 101003001&&scope.row.orderStatus !== 101001001&&scope.row.paymentType===102002001"
                           class="f-wa f-ml10 f-mt5 f-mb5"
                           @click="orderPay(scope.row,'订单支付成功')">
                  确认支付
                </el-button>
                <el-button type="primary"
                           v-if="scope.row.isDelete === 111002001&&scope.row.orderStatus === 101001001"
                           class="f-wa f-ml10 f-mt5 f-mb5"
                           @click="deleteOrder(scope.row.id,'notarizeDelete','订单删除成功')">确认删除
                </el-button>
                <el-button type="primary"
                           v-if="scope.row.isDelete === 111002001&&scope.row.orderStatus === 101001001"
                           class="f-wa f-ml10 f-mt5 f-mb5"
                           @click="deleteOrder(scope.row.id,111002002,'订单还原成功')">还原
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination class="f-mt10"
                         :current-page="currentPage"
                         :page-size="pageSize"
                         @size-change="handleSizeChange"
                         @current-change="handleCurrentChange"
                         layout="total,sizes,prev, pager, next, jumper"
                         :total="total" style="float: right">
          </el-pagination>
        </div>
      </el-col>
    </el-row>

    <!--反馈跟踪Dialog-->
    <el-dialog title="物流状态" :visible.sync="feedbackTracking" size="tiny">
      <el-form :model="logisticsStatusForm">
        <el-form-item label="跟踪人员" :label-width="120">
          <el-input class="f-w70"></el-input>
        </el-form-item>
        <el-form-item label="跟踪时间" :label-width="120">
          <el-input class="f-w70"></el-input>
        </el-form-item>
        <el-form-item label="跟踪方式" :label-width="120">
          <el-input class="f-w70"></el-input>
        </el-form-item>
        <el-form-item label="跟踪节点" :label-width="120">
          <el-input class="f-w70"></el-input>
        </el-form-item>
        <el-form-item label="当前地址" :label-width="120">
          <el-select class="f-w70" v-model="logisticsStatusForm.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="跟踪描述" :label-width="120">
          <el-select class="f-w70" v-model="logisticsStatusForm.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button class="f-wa" @click="dialogFormVisible = false">取 消</el-button>
        <el-button class="f-wa" type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>

    <!--接待录入Dialog-->
    <el-dialog title="待录入" :visible.sync="receptionEntering" size="large">
      <el-form :model="logisticsStatusForm">
      </el-form>
      <div slot="footer">
        <el-button class="f-wa" @click="dialogFormVisible = false">取 消</el-button>
        <el-button class="f-wa" type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>

    <!--订单录入Dialog-->
    <el-dialog title="订单录入" style="top: 5%;" :visible.sync="orderEnteringDialog" size="large">
      <order-entering></order-entering>
    </el-dialog>

    <!--订单查看Dialog-->
    <el-dialog title="订单查看" :visible.sync="orderSelect" width="80%">
      <order-select :title="orderSelectForm"></order-select>
    </el-dialog>

    <!--订单支付-->
    <el-dialog title="付款确认" size="tiny" :visible.sync="paymentAffirm">
      <div style="background: #F2F2F2;">
        <el-row class="f-pt10 f-mb0">
          <el-col :span="12">
            <div class="grid-content f-ml10">订单编号：<label v-html="orderNumberPayHtml"></label></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content">订单运费：<label v-html="orderFreight"></label></div>
          </el-col>
        </el-row>
        <el-row class="f-mb0">
          <el-col :span="12">
            <div class="grid-content f-ml10">结算方式：<label v-html="orderPaymentType"></label></div>
          </el-col>
        </el-row>
        <el-row class="f-mb0">
          <el-col :span="24">
            <div class="grid-content bg-purple-dark">
              <div class="f-tar f-mt10 f-mb10" style="border: 1px solid #e6be13;background: #FFFBEA">
                <div style="width: 50%;text-align: left;line-height: 28px;background: #fffbea">
                  <li style="width: 55%;float: left" v-html="couponLogNumber"></li>
                </div>
                <el-button type="text" class="f-wa" @click="couponLogSumbit('this')">马上使用>></el-button>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="grid-content bg-purple-dark f-ml10 f-cr">应收总金额：<label
              v-html="orderTotalMoney"></label></div>
          </el-col>
        </el-row>
      </div>
      <el-row class="f-mb0" style="display: none">
        <el-col :span="24" class="f-ml10 f-mt10">
          <div class="grid-content bg-purple-dark">
            <el-radio class="radio" v-model="orderPayRadio" label="accountPay"> 账户余额：可支付余额: 0元</el-radio>
          </div>
        </el-col>
      </el-row>
      <el-row class="f-mb0">
        <el-col :span="24" class="f-ml10">
          <div class="grid-content bg-purple-dark">其他支付方式</div>
        </el-col>
      </el-row>
      <el-row style="background: #F2F2F2;">
        <el-col :span="24" class="f-mb20 f-ml10">
          <div class="grid-content bg-purple-dark">
            <div class="grid-content">
              <div>
                <p>请选择一下支付方式的一种</p>
                <el-row class="f-pb10 f-pl10">
                  <el-col :span="8">
                    <el-radio class="radio" v-model="orderPayRadio" label="aliPay">
                      <img src="../../assets/aliPayLogo.png" class="f-w80"></el-radio>
                  </el-col>
                  <el-col :span="8">
                    <el-radio class="radio" v-model="orderPayRadio" label="weChatPay"><img
                      src="../../assets/weChatLogo.png" class="f-w80"></el-radio>
                  </el-col>
                  <el-col :span="8">
                    <el-radio class="radio" v-model="orderPayRadio" label="unionPay"><img
                      src="../../assets/unionPayLogo.png" class="f-w80"></el-radio>
                  </el-col>
                </el-row>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
                <el-button @click="paymentAffirm = false" class="f-wa">取 消</el-button>
                <el-button type="primary" @click="pay" class="f-wa">确 定</el-button>
            </span>
    </el-dialog>
    <el-dialog title="优惠券" :visible.sync="couponLogDialog">
      <el-table :data="couponLogData" highlight-current-row border style="width: 100%;">
        <el-table-column prop="name" label="优惠券名称" width="150">
        </el-table-column>
        <el-table-column prop="typeName" label="类型" width="80">
        </el-table-column>
        <el-table-column prop="statusName" label="状态" width="80">
        </el-table-column>
        <el-table-column prop="faceValue" label="面值/折扣" width="80">
          <template slot-scope="faceValue">
            <li v-if="faceValue.row.typeName=='抵用券'" style="list-style: none">
              {{faceValue.row.faceValue}}
            </li>
            <li v-if="faceValue.row.typeName=='折扣券'" style="list-style: none">
              {{faceValue.row.faceValue}}%
            </li>
          </template>
        </el-table-column>
        <el-table-column prop="agingType" label="时效">
          <template slot-scope="aging">
            <li v-if="aging.row.agingType==0" style="list-style: none">
              {{aging.row.effectiveBeginDate.substring(0, aging.row.effectiveBeginDate.length - 9)}}到{{aging.row.effectiveEndDate.substring(0, aging.row.effectiveBeginDate.length - 9)}}
            </li>
            <li v-if="aging.row.agingType==1" style="list-style: none">
              领取后 :{{aging.row.days}} 天内使用
            </li>
          </template>
        </el-table-column>
        <el-table-column prop="grantType" label="发放方式">
          <template slot-scope="grantTypeCode">
            <li v-if="grantTypeCode.row.agingType==0" style="list-style: none">
              用户领取
            </li>
            <li v-if="grantTypeCode.row.agingType==1" style="list-style: none">
              直接赠送
            </li>
          </template>
        </el-table-column>
        <el-table-column prop="userlevel" label="适用范围">
          <template slot-scope="useRange">
            <li v-if="useRange.row.rangeType==0" style="list-style: none">
              用户等级
            </li>
            <li v-if="useRange.row.rangeType==1" style="list-style: none">
              注册时间
            </li>
            <li v-if="useRange.row.rangeType==2" style="list-style: none">
              活跃度
            </li>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button  @click="selectCouponLog(scope.row)">使用
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog title="请使用微信客户端扫一扫支付" :visible.sync="wechatQRCodeDialog"
               size="tiny">
      <div v-html="QRCodehtml">
      </div>
    </el-dialog>

  </div>
</template>
<script>
import {
  getOrderTableDataUser,
  orderReverse,
  deleteOrder,
  notarizeDeleteOrder, searchOrderNumbersUser
} from '../../api/order/order.js';
import { getDictEntityByDictCode } from '../../api/system/Dict.js';
import { isEmpty } from '../../lib/util.js';
import OrderEntering from './OrderEnteringDialog.vue';
import OrderSelect from './OrderSelectDialog.vue';
import { getReceivesByPhone } from '../../api/marketing/couponApi.js';
import { aliPay, accountPay, unionPay, wechatPay, payments } from '../../api/pay/pay.js';

export default {
  components: {
    'order-entering': OrderEntering,
    'order-select': OrderSelect
  },
  data () {
    return {
      token: this.$store.state.token,
      userId: this.$store.state.userId,
      paymentAffirm: false,
      couponLogDialog: false,
      orderPayRadio: '',
      orderNumberPayHtml: '',
      orderFreight: '',
      payOrderPrice: '',
      orderPaymentType: '',
      orderTotalMoney: '',
      couponLogNumber: '',
      wechatQRCodeDialog: false,
      QRCodehtml: '',
      thisOrder: {},
      thisCouponLog: {},
      couponLogData: [], // 优惠券弹框
      fs: '',
      orderSelectForm: {},
      isAwaitSubmit: true,
      isAwaitAssert: true,
      isAwaitPay: true,
      isAwaitAssign: true,
      isAwaitExtract: true,
      isDelete: true,
      stopPayWeChat: '',

      orderEnteringDialog: false,
      orderSelect: false,
      selectDispatchCentre: false,
      refresh: '',
      feedbackTracking: false,
      receptionEntering: false,
      logisticsStatusForm: {},
      searchForm: {
        orderNumber: null,
        createDate: null,
        orderSource: null,
        memberUserName: null,
        shipmentsContactName: null,
        shipmentsTelephone: null// 发货人--固定电话
      },
      orderSources: [],
      multipleSelection: [],
      orderNumbers: {
        all: '',
        dtj: '', // 代提交
        dqr: '', // 待确认
        dzf: '', // 待支付
        dqs: '', // 待签收
        dth: '', // 待提货
        hsz: ''// 回收站
      },
      total: 0,
      currentPage: 1,
      pageSize: 10,
      orderTableData: [],
      dispatchCentreData: [],
      orderIds: [],
      orderRowData: [],
      orderShipments: {
        shipmentsProvinceId: '',
        shipmentsCityId: '',
        shipmentsCountyId: ''
      }
    };
  },
  methods: {

    pay () {
      switch (this.orderPayRadio) {
        case 'accountPay':
          accountPay({
            orderId: this.thisOrder.id, // 订单id
            couponId: this.thisCouponLog.couponId, // 优惠券id
            couponUseId: this.thisCouponLog.id// 优惠券领用id
          }).then((res) => {
            window.document.write(res.data);
          });
          break;
        case 'aliPay':
          aliPay({
            orderId: this.thisOrder.id, // 订单id
            couponId: this.thisCouponLog.couponId, // 优惠券id
            couponUseId: this.thisCouponLog.id// 优惠券领用id
          }).then((res) => {
            console.log(res.data);
            window.document.write(res.data);
          });
          break;
        case 'weChatPay':
          wechatPay({
            orderId: this.thisOrder.id, // 订单id
            couponId: this.thisCouponLog.couponId, // 优惠券id
            couponUseId: this.thisCouponLog.id// 优惠券领用id
          }).then((res) => {
            this.wechatQRCodeDialog = true;
            let com = 'http://qr.liantu.com/api.php?text=';
            let url = com + res.data.obj.codeUrl;
            this.QRCodehtml = '<img style="width: 100%;margin: auto" src=' + url + ' />';
            this.stopPayWeChat = setInterval(() => {
              console.log(res.data.obj.serialNo);
              this.refreshOrderPayWeChat(res.data.obj.serialNo);
            }, 5000);
          });
          break;
        case 'unionPay':
          unionPay({
            orderId: this.thisOrder.id, // 订单id
            couponId: this.thisCouponLog.couponId, // 优惠券id
            couponUseId: this.thisCouponLog.id// 优惠券领用id
          }).then((res) => {
            console.log(res.data);
            window.document.write(res.data);
          });
          break;
      }
    },

    refreshOrderPayWeChat (val) {
      payments(val).then((res) => {
        console.log(res.data.obj);
        if (res.data.obj.successFlg) {
          clearInterval(this.stopPayWeChat);
          this.$message.success('支付成功');
          location.reload();
        }
      });
    },

    /**
       *
       * 使用优惠券
       */
    selectCouponLog (row) {
      this.thisCouponLog = row;
      if (row.type === 114001002) {
        this.orderTotalMoney = parseFloat(this.payOrderPrice * (row.faceValue / 100));
      } else {
        this.orderTotalMoney = parseFloat(this.payOrderPrice - row.faceValue);
      }

      this.couponLogDialog = false;
    },
    couponLogSumbit (val) {
      if (val === 'this') {
        this.couponLogDialog = true;
      }
      getReceivesByPhone({
        user_id: this.userId,
        expired: 'false',
        enabled: 'true',
        filters: this.thisOrder.orderPrice,
        sorts: '',
        size: '15',
        page: '1'
      }).then((res) => {
        if (res.data.successFlg) {
          this.couponLogData = res.data.detailModelList;
          this.couponLogNumber = '您有 ' + res.data.detailModelList.length + ' 张可用优惠券';
        }
      });
    },
    /**
       * 订单支付
       */
    orderPay (row, msg) {
      if (row.paymentType !== 102002001) {
        return this.$message.error('目前只支持现付付款方式');
      }

      this.thisOrder = row;
      this.couponLogSumbit();
      this.payOrderPrice = row.orderPrice;
      this.paymentAffirm = true;
      this.orderNumberPayHtml = row.orderNumber;
      this.orderFreight = row.orderPrice;
      this.orderPaymentType = '现付';
      this.orderTotalMoney = row.orderPrice;
    },
    /**
       * 查看订单
       */
    orderSelectDialog (val) {
      this.orderSelect = true;
      this.orderSelectForm = val;
    },
    /**
       * 删除订单
       */
    deleteOrder (id, isDelete, msg) {
      if (isEmpty(id)) {
        return this.$message.error('请选择您要更改的订单');
      }

      this.$confirm('您确定要删除该订单', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // （物理删除）
        if (isDelete === 'notarizeDelete') {
          notarizeDeleteOrder(this.token, id).then((res) => {
            if (res.data.successFlg) {
              this.$message.success(msg);
              this.searchOrderTable('isDelete=111002002');
            }
          });
        } else {
          // （逻辑删除）
          deleteOrder(this.token, id, isDelete).then((res) => {
            if (res.data.successFlg) {
              this.$message.success(msg);
              this.searchOrderTable('isDelete=111002002');
            }
          });
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    /**
       * 反馈跟踪
       */
    feedbackTrackingDialog () {
      this.feedbackTracking = true;
    },

    /**
       * 表格多选
       */
    scOrders (orders) {
      this.orderIds = [];
      this.orderRowData = orders;
      for (let order in orders) {
        this.orderIds.push(orders[order].id);
      }
      this.orderIds = this.orderIds.join();
    },
    orderReverse (id, status, refresh, msg) {
      if (isEmpty(id)) {
        return this.$message.error('请选择您要更改的订单');
      }

      this.$confirm('您确认要改变该订单状态', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        orderReverse(this.token, id, status).then((res) => {
          if (res.data.successFlg) {
            this.$message.success(msg);
            this.searchOrdersByOrderStatus('orderStatus=' + refresh);
          }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },
    searchOrderSource () {
      getDictEntityByDictCode({token: this.token, dictCode: 101004}).then((res) => {
        this.orderSources = res.data.detailModelList;
      });
    },

    searchOrdersByOrderStatus (filters) {
      this.fs = filters;

      if (isEmpty(filters)) {
        //                    this.isAwaitSubmit = false;
        //
        //                    this.isAwaitAssert = false;
        //                    this.isAwaitPay = false;
        //                    this.isAwaitAssign = false;
        //                    this.isAwaitExtract = false;
        //                    this.isDelete = false;
      } else if (filters === 'orderStatus=101001001 g0;isDelete=111002002 g1') {
        // 代提交
        this.isAwaitSubmit = false;

        this.isAwaitAssert = true;
        this.isAwaitPay = true;
        this.isAwaitAssign = true;
        this.isAwaitExtract = true;
        this.isDelete = true;
      } else if (filters === 'orderStatus=101001002 g0') {
        // 待确认
        this.isAwaitAssert = false;

        this.isAwaitSubmit = true;
        this.isAwaitPay = true;
        this.isAwaitAssign = true;
        this.isAwaitExtract = true;
        this.isDelete = true;
      } else if (filters === 'payStatus=101003001 g0;isDelete<>111002001 g1') {
        // 待支付
        this.isAwaitPay = false;

        this.isAwaitSubmit = true;
        this.isAwaitAssert = true;
        this.isAwaitAssign = true;
        this.isAwaitExtract = true;
        this.isDelete = true;
      } else if (filters === 'signOffStatus=101009001 g0') {
        // 待签收
        this.isAwaitAssign = false;

        this.isAwaitPay = true;
        this.isAwaitSubmit = true;
        this.isAwaitAssert = true;
        this.isAwaitExtract = true;
        this.isDelete = true;
      } else if (filters === 'orderStatus=101001007 g0') {
        // 待签收
        this.isAwaitExtract = false;

        this.isAwaitAssign = true;
        this.isAwaitPay = true;
        this.isAwaitSubmit = true;
        this.isAwaitAssert = true;
        this.isDelete = true;
      } else if (filters === 'isDelete=111002001 g0') {
        // 回收站
        this.isDelete = false;

        this.isAwaitExtract = true;
        this.isAwaitAssign = true;
        this.isAwaitPay = true;
        this.isAwaitSubmit = true;
        this.isAwaitAssert = true;
      }

      this.searchOrderTable(filters);
    },

    /**
       * 多条件检索订单信息
       */
    searchOrders () {
      this.fs = '';
      let sf = this.searchForm;
      let filters = '';
      for (let s in sf) {
        if (sf[s] == null || sf[s] === undefined || sf[s] === '') {
          continue;
        }

        if (s === 'createDate') {
          let startDate = (sf[s][0]).Format('yyyy-MM-dd');
          let endDate = (sf[s][1]).Format('yyyy-MM-dd');
          filters += s + '>=' + startDate + ';' + s + '<=' + endDate + ';';
          continue;
        }
        if (s === 'orderSource') {
          filters += s + '=' + sf[s] + ';';
          continue;
        }
        if (s === 'shipmentsTelephone') {
          filters += s + '?' + sf[s] + ' g8;shipmentsContactPhone?' + sf[s] + ' g8';
          continue;
        }
        filters += s + '?' + sf[s] + ';';
      }
      this.searchOrderTable(filters);
    },

    /**
       * 检索订单信息
       * @param filters
       */
    searchOrderTable (filters) {
      if (isEmpty(filters)) {
        filters = 'EQ_memberUserId=' + this.userId + ';';
      } else {
        filters += ';EQ_memberUserId=' + this.userId + ';';
      }
      getOrderTableDataUser({
        token: this.token,
        filters: isEmpty(this.fs) ? filters : this.fs + ';EQ_memberUserId=' + this.userId + ';',
        sorts: '-createDate',
        size: this.pageSize,
        page: this.currentPage
      }).then((res) => {
        if (res.data.successFlg === true) {
          // 总订单数量 = 总订单-回收站
          if (isEmpty(this.orderNumbers.all)) {
            this.orderNumbers.all = res.data.totalCount - this.orderNumbers.hsz;
          }
          this.orderTableData = res.data.detailModelList;
          this.currentPage = res.data.currPage;
          this.total = res.data.totalCount;
          this.pageSize = res.data.pageSize;
        }
      });

      /**
         * 检索各状态的订单数量
         * @type {{101001001: string, 101001002: string, 101003002: string, 101001003: string, 101001004: string, 111002001: string}}
         */
      let orderStatusFilters = {
        101001001: 'orderStatus=101001001 g0;isDelete=111002002 g1;memberUserId=' + this.userId + ' g10', // 待提交
        101001002: 'orderStatus=101001002 g0;memberUserId=' + this.userId + ' g10', // 待确认
        101003002: 'payStatus=101003001 g0;isDelete=111002002 g1;memberUserId=' + this.userId + ' g10', // 待支付
        101009001: 'signOffStatus=101009001 g0;memberUserId=' + this.userId + ' g10', // 待签收
        101001007: 'orderStatus=101001007 g0;memberUserId=' + this.userId + ' g10', // 待评价
        111002001: 'isDelete=111002001 g0;memberUserId=' + this.userId + ' g10' // 回收站
      };
      searchOrderNumbersUser({
        token: this.token,
        filters: JSON.stringify(orderStatusFilters),
        //                    filters: "orderStatus=101001001,orderStatus=101001002,orderStatus=101001003,orderStatus=101001004,orderStatus=101001005,signOffStatus=101009001,payStatus=101003002,isDelete=111002001",
        sorts: ''
      }).then((res) => {
        let numData = res.data.detailModelList;
        for (let ons in numData) {
          switch (numData[ons].orderStatus) {
            case '101001001':
              // 待提价
              this.orderNumbers.dtj = numData[ons].orderStatusNumber === '' ? 0 : numData[ons].orderStatusNumber;
              break;
            case '101001002':
              // 待确认
              this.orderNumbers.dqr = numData[ons].orderStatusNumber === '' ? 0 : numData[ons].orderStatusNumber;
              break;
            case '101003002':
              // 待支付
              this.orderNumbers.dzf = numData[ons].orderStatusNumber === '' ? 0 : numData[ons].orderStatusNumber;
              break;
            case '101009001':
              // 待签收
              this.orderNumbers.dqs = numData[ons].orderStatusNumber === '' ? 0 : numData[ons].orderStatusNumber;
              break;
            case '101001007':
              // 待评价
              this.orderNumbers.dth = numData[ons].orderStatusNumber === '' ? 0 : numData[ons].orderStatusNumber;
              break;
            case '111002001':
              // 回收站
              this.orderNumbers.hsz = numData[ons].orderStatusNumber === '' ? 0 : numData[ons].orderStatusNumber;
              break;
          }
        }
      });
    },

    // 每页几条操作
    handleSizeChange (val) {
      this.pageSize = val;
      this.searchOrderTable();
    },
    // 第几页操作
    handleCurrentChange (val) {
      this.currentPage = val;
      this.searchOrderTable();
    },
    resetSearchForm (formName) {
      this.$refs[formName].resetFields();
    }
  },

  mounted () {
    this.searchOrderTable();
  }
};
</script>
